package demo3;
//usb接口
interface USB{
    double brand = 3.0;

//    public USB(){
//
//    } error

//    static {
//
//    } error


    void openDevicd();
    void closeDevied();

    default void operate(){
        System.out.println("操作usb设备");
    } //ok
}



public class Test{
    public static void main(String[] args) {
        System.out.println(USB.brand);//可以通过接口名访问，说明是静态的

        //USB.brand = 2.0;//error 说明brand具有final属性
    }
}









//鼠标类，实现USB接口
class Mouse implements USB{
//    private void openDevicd(){
//        System.out.println("打开鼠标");
//    } //error


//    void closeDevied(){
//        System.out.println("关闭鼠标");
//    } //error


    @Override
    public void openDevicd() {
        System.out.println("打开鼠标");
    }

//    @Override
//    void closeDevied() {
//        System.out.println("关闭鼠标");
//    }   error

    @Override
     public void closeDevied() {
        System.out.println("关闭鼠标");
    }

    public void click(){
        System.out.println("鼠标点击");
    }
}

//键盘类 实现USB接口
class KeyBoard implements USB{

    @Override
    public void openDevicd() {
        System.out.println("打开键盘");
    }

    @Override
    public void closeDevied() {
        System.out.println("关闭键盘");
    }

    public void input(){
        System.out.println("键盘输入");
    }
}

//笔记本类：使用USB设备
class Computer{
    public void powerOn(){
        System.out.println("打开电脑");
    }
    public void powerOff(){
        System.out.println("关闭电脑");
    }

    public void useDevied(USB usb){
        usb.openDevicd();
        if(usb instanceof Mouse){
            Mouse mouse = (Mouse)usb;///向下转型
            mouse.click();
        }else if(usb instanceof KeyBoard){
            KeyBoard keyBoard = (KeyBoard) usb;
            keyBoard.input();
        }
        usb.closeDevied();
    }

}
 abstract class TestDemop implements USB{

 }
//public class Test {
//    public static void main(String[] args) {
//        Computer computer = new Computer();
//        //使用鼠标设备
//        computer.useDevied(new Mouse());
//        //使用键盘设备
//        computer.useDevied(new KeyBoard());
//
//        computer.powerOff();
//    }
//}
